import com.entity.Dbrole;
import com.entity.Dbuser;
import com.mapper.BookMapper;
import com.mapper.DbuserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017/6/22.
 */
public class DomUserROle {
    protected SqlSessionFactory sf;
    protected SqlSession ss;
    protected BookMapper bdao;
    protected DbuserMapper dbuser;
    protected DbuserMapper dbuser02;
    @Before
    public void init(){

        try {
            this.sf=new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml"));
            this.ss=this.sf.openSession();
            bdao= this.ss.getMapper(BookMapper.class);
            dbuser= this.ss.getMapper(DbuserMapper.class);
            dbuser02=this.ss.getMapper(DbuserMapper.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @After
    public void  close(){
        this.ss.commit();
        this.ss.close();
    }
    @Test
    public void show(){
       Dbuser dbu= dbuser.findById(1);
        System.out.println(dbu.getPass());

        List<Dbrole> role =dbu.getDbroles();
        for(Dbrole ddu : role){
            System.out.println(ddu.getName());
        }

        /*List<Map<String,Object>>  list= dbuser.findAll();
        for(Map<String,Object> mm: list){
            System.out.println(mm);
            System.out.println(mm.get("pass"));
            System.out.println(mm.get("uname"));
        }*/
    }
}
